<template>
	<view>
		<navbar :isback="true" :title="title"></navbar>
		<u-sticky bgColor="#fff" v-if="poplist.length>0" customNavHeight="44">
			<view class="tab">
				<u-tabs :list="poplist" lineWidth="71rpx" lineHeight='10rpx' lineColor="#0381FC" :activeStyle="{
				            color: '#1E1E1E',
				            fontWeight: 'bold',
				            transform: 'scale(1.15)'
				        }" :inactiveStyle="{
				            color: '#1E1E1E',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 40rpx; padding-right: 40rpx; height: 50rpx;font-size:26rpx;" @click="clicktab"
					:current='current'>
				</u-tabs>
			</view>
		</u-sticky>
		<u-loading-page icon-size="100rpx" :loading="loading" loading-text="驼乡生活信息超市"></u-loading-page>
		<view class="" v-if="!loading">
			<view class="" v-if="msglist.length>0">
				<fbmsgitem :item="item" v-for="(item,index) in msglist" :key="index" @xj='clickxj(item,index)'
					@del='clickdel(item)'></fbmsgitem>
			</view>
			<view class="" v-else style="padding-top: 50rpx;">
				<u-empty mode="list" text="暂无消息">
				</u-empty>
			</view>
		</view>

		<u-safe-bottom></u-safe-bottom>
		<view class="kf">
			<button class="u-reset-button" open-type="contact">
				<image src="/static/xishi/kf.png" class="kficon" mode=""></image>
			</button>
		</view>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	import home from '@/api/_home.js'
	import {
		BASE_URL
	} from '@/api/config';
	export default {
		data() {
			return {
				loading: true,
				title: '',
				status: 2,
				poplist: [{
						name: '显示中',
						status: 2,
						text:'xianshi',
						badge: {
							value: 0,
						}
					},
					{
						name: '待审核',
						status: 1
					},
					{
						name: '已过期',
						status: 3
					},
					{
						name: '审核失败',
						status: 4,
						text:'shibai',
						badge: {
							value: 0,
						}
					},
				],
				msglist: [],
				type: '',
				short_type: '',
				current: 0
			};
		},
		onLoad(o) {
			this.title = o.title
			this.short_type = o.short_type
			this.type = o.type
			if (o.cur) {
				this.status = this.poplist[o.cur].status
				this.current = o.cur
			}
			// this.getlist()
		},
		onShow() {
			this.getlist()
			this.getnum()
		},
		methods: {
			getnum(){
				user.infoContentCount({type:this.type,short_type:this.short_type}).then(res=>{
					if(res.data.code==1){
						for (let key in res.data.data) {
							this.poplist.map(t=>{
								if(t.text==key){
									t.badge.value=res.data.data[key]
								}
							})
						}
					}
				})
			},
			clickxj(item, index) {
				let _this = this
				uni.showModal({
					title: '确认下架该信息？',
					success(r) {
						if (r.confirm) {
							home.changeStatus({
								id: item.id,
								status: 3
							}).then(res => {
								if (res.data.code == 1) {
									uni.$u.toast('下架成功')
									_this.status = 3
									_this.current = 2
									_this.getlist()
								}
							})
						}
					}
				})
			},
			clickdel(item) {
				let _this = this
				uni.showModal({
					title: '确认删除该信息？',
					success(r) {
						if (r.confirm) {
							home.delInfo({
								id: item.id
							}).then(res => {
								if (res.data.code == 1) {
									uni.$u.toast('删除成功')
									_this.getlist()
								}
							})
						}
					}
				})
			},
			clicktab(e) {
				// console.log(e)
				this.status = e.status
				this.getlist()
				this.$forceUpdate()
			},
			getlist() {
				home.infoList({
					short_type: this.short_type,
					type: this.type,
					status: this.status
				}).then(res => {
					if (res.data.code == 1) {
						this.msglist = res.data.data
						this.loading = false
						this.msglist.map(t => {
							t.imags = []
							t.imag = t.ad_images.split(',')
							if (t.imag[0] == '') {
								t.imag = []
							}
							t.imag.map(t1 => {
								t.imags.push(BASE_URL + t1)
							})
						})
						// console.log(this.msglist)
						this.$forceUpdate()
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.tab {
		padding: 30rpx 0 20rpx;
	}
</style>